#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define getchar() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=getchar();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x*=f;
    }
}
using namespace IO;
const int N=2e5+5;
int n,suf[N];
struct node{int a,b;}a[N];
inline bool cmp(node x,node y){return x.b>y.b;}
long long ans=1e15;
int main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i) read(a[i].a),read(a[i].b);
	sort(a+1,a+n+1,cmp);
	suf[n]=a[n].a;
	for(int i=n-1;i;--i) suf[i]=min(suf[i+1],a[i].a);
	long long mi=1e15;
	for(int i=1;i<n;++i){
		ans=min(mi+a[i].a+a[i].b+suf[i+1],ans);
		mi=min(mi,1ll*a[i].a+a[i].b);
	}
	printf("%lld\n",ans);
	return 0;
}

